package cn.xutongxue.interview.common;

import cn.xutongxue.interview.enums.Errors;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author Administrator
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseResult<T> implements Serializable {

    /**
     * 状态 ok:正常 fail:失败
     */
    private String status;
    /**
     * 返回信息
     */
    private String msg;
    /**
     * 状态码
     */
    private Integer code;
    /**
     * 返回体
     */
    private T data;

    public static <T> ResponseResult<T> ok() {
        return new ResponseResult<>("ok", "请求成功", 20000, null);
    }

    public static <T> ResponseResult<T> ok(T data) {
        return new ResponseResult<>("ok", "请求成功", 20000, data);
    }

    public static <T> ResponseResult<T> ok(String msg, T data) {
        return new ResponseResult<>("ok", msg, 20000, data);
    }

    public static <T> ResponseResult<T> fail(String msg) {
        return new ResponseResult<>("fail", msg, 50000, null);
    }

    public static <T> ResponseResult<T> fail(String msg, Integer code) {
        return new ResponseResult<>("fail", msg, code, null);
    }

    public static <T> ResponseResult<T> fail(Errors error) {
        return new ResponseResult<>("fail", error.getMessage(), error.getCode(), null);
    }

}
